import React, { FC, useContext } from 'react';
import { View, Text } from '@tarojs/components';
import { styled } from 'linaria/react';
import { useClassName } from '@/utils/index';
import { ProductCardContext } from '@/pages/components/ProductCard/ProductCardContext';

export interface IProps extends ICompProps {}
ProductTitle.defaultProps = {} as Partial<IProps>;
function ProductTitle(props: IProps) {
    const { className, style } = props;
    const localClassName = useClassName('ProductTitle', className);
    const { title, subTitle } = useContext(ProductCardContext);
    return (
        <RootView className={localClassName} style={style}>
            <View className="title text-overflow">{title}</View>
            <View className="sub-title text-overflow">{subTitle}</View>
        </RootView>
    );
}
export default React.memo(ProductTitle as FC<IProps>);
const RootView = styled(View)`
    &.ProductTitle {
        .title {
            font-size: 32px;
            font-weight: 500;
            color: #333333;
            height: 32px;
            line-height: 32px;
        }
        .sub-title {
            font-size: 26px;
            font-weight: 400;
            color: #808a9d;
            height: 26px;
            line-height: 26px;
            margin-top: 20px;
        }
        .text-overflow {
            width: 100%;
            overflow: hidden; /*超出隐藏*/
            text-overflow: ellipsis; /*隐藏后添加省略号*/
            white-space: nowrap; /*强制不换行*/
        }
    }
`;
